package org.zhang.shortlink.admin.remote.api;


import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.TypeReference;
import org.springframework.web.bind.annotation.RequestParam;
import org.zhang.shortlink.admin.remote.dto.resp.ShortLinkGroupCountVO;
import org.zhang.shortlink.common.convention.result.Result;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: 张嘉庆
 * @date: 2024/4/13 20:10
 * @description: 后续重构为OpenFeign
 */

public interface ShortLinkRemoteService {
    default Result<List<ShortLinkGroupCountVO>> listGroupShortLinkCount(List<String> requestParam) {
        Map<String, Object> reqMap = new HashMap<>();
        reqMap.put("requestParam", requestParam);
        String resultPageStr = HttpUtil.get("http://localhost:56002/api/short-link/link/v1/count", reqMap);
        return  JSON.parseObject(resultPageStr,new TypeReference<>(){});
    }

    /**
     * 获取指定网站的标题
     */
    default Result<String> getTitleByUrl(@RequestParam("url") String url) {
        String resultStr = HttpUtil.get("http://127.0.0.1:56002/api/short-link/v1/title?url="+url);
        System.out.println(resultStr);
        return  JSON.parseObject(resultStr,new TypeReference<>(){});
    }
}
